using System;
using System.Collections.Generic;
using UnityEngine;

namespace RewiredConsts.__Naptime
{
	public class ScriptableObjectService : MonoBehaviour
	{
		[SerializeReference]
		private DynamicIconChangerConfig dynamicIconChangerConfig;

		private Dictionary<Type, object> _localizations;

		public static ScriptableObjectService Instance { get; private set; }

		public static bool IsInit { get; private set; }

		private void Awake()
		{
			if (IsInit)
			{
				UnityEngine.Object.Destroy(this);
				return;
			}
			InitLocalizations();
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
			IsInit = true;
			Instance = this;
		}

		private void InitLocalizations()
		{
			_localizations = new Dictionary<Type, object> { 
			{
				typeof(DynamicIconChangerConfig),
				dynamicIconChangerConfig
			} };
		}

		public void AddService<T>(T service)
		{
			if (!_localizations.ContainsKey(typeof(T)))
			{
				_localizations.Add(typeof(T), service);
			}
		}

		public bool TryGetService<T>(out T service)
		{
			if (!_localizations.ContainsKey(typeof(T)))
			{
				service = default(T);
				return false;
			}
			service = (T)_localizations[typeof(T)];
			return true;
		}
	}
}
